The present invention relates generally to a method and apparatus for improving performance of multi-threaded computer programs by reducing contention for computer memory. More particularly the present invention re-establishes the lock structure used by multi-threaded computer programs to enable greater resolution of the region of memory that is associated with the lock structure.
Compiler systems operating in a computer system typically access computer resources such as computer memory. One method of computer resource access is threads-based programming that operates with a compiler system to enable an activity generated by program code to proceed asynchronously with respect to other activities executing in the computer system.
It will be appreciated that the term xe2x80x9cthreadxe2x80x9d refers to a linear control flow of an executing program, and in a multi-threaded environment several paths in an executing program may be executing simultaneously. Threads may be programmed to execute sequentially or concurrently. Many computer systems include multiple processors and therefore concurrent execution of threads-based programs may take advantage of the hardware concurrence built into computer systems that include multiple processors. The concurrent operation of a threads-based program creates the need to safeguard the state of variables associated with the threads-based program while the threads-based program is accessing computer memory.
When multiple threads are dependent each thread may send messages to objects or processes that are associated with the other threads. A consistent state may be maintained for the variables in an object or process associated with a thread by methods such as, synchronizing the operations of associated threads or safeguarding the operations associated with the threads. It will be appreciated that safeguarding may be accomplished by structural exclusion techniques. The term xe2x80x9cstatexe2x80x9d as used herein refers to the value associated with a variable that is maintained in a consistent manner.
Shared computer memory is accessible by two or more threads. Therefore, multi-threaded programs acquire access to portions of the computer memory in order to execute the threaded instructions in the appropriate sequence. Typically, a lock structure is created by the compiler system to ensure that access to a region, or portion, of the computer memory is safeguarded. It would be advantageous if the lock structure used for safeguarding were re-structured based on the references to a portion of the memory and not on the process of execution of the code block. Thereby the lock structure would enable greater resolution of the region of the memory that is locked and less contention for access to computer memory than in the past.
The present invention is a method and apparatus for improving performance of multi-threaded computer programs by reducing contention for computer memory. More particularly, the present invention re-establishes the lock structure that enables access to a portion of the computer memory.
Many compilation systems include operations to improve performance of programs that may include multi-threaded operations. The present invention extends the capabilities of a compilation system by analyzing the references to computer memory and thereby improves the use of regions of computer memory that are found to be mutually exclusive. Therefore, the present invention may operate in cooperation with a compilation system that may include an interpreter, an emulator such as the product marketed under the trademark JAVA Virtual Machine,(trademark) a run-time compiler, or any other operation that accesses computer memory. More particularly the present invention advantageously re-establishes a lock structure that may be used with threads-based programs to safeguard regions of computer memory.
Accordingly it is an object of the invention to determine the computer-based operation that the locks are safeguarding and to re-establish a lock structure based on the reference to the memory made by the safeguarded operation. For example, the product marketed under the trademark JAVA(trademark) operates to manage information about the region of the computer memory that is accessed during the execution of a software program. The present invention takes advantage of that operation. More particularly, the present invention may analyze a critical code block to determine the region of the memory accessed by the critical code block and may re-establish access and safeguarding of the memory based on the reference made by the operation to the memory.
It will be appreciated that a critical code block is a subset of a code block. The term xe2x80x9ccode blockxe2x80x9d as used herein refers to a sequence of instructions that execute on a computer system and threads-based program code may operate on a code block. The term xe2x80x9ccritical code blockxe2x80x9d as used herein refers to a sequence of instructions that begins with the code that is associated with the acquisition of a lock and ends with the code that is associated with the release of the lock.
It is an object of the invention to re-establish the access by a threads-based program to a lock via reference to the memory. In the past access by a threads-based program to a lock was based on access to information about the process of execution of the critical code block associated with the thread.
It is also an object of the present invention to enable greater sharing of the computer memory by a more efficient access to the computer memory than in the past. It will be appreciated that efficient access to the computer memory is achieved when concurrent access to the memory is enabled. Therefore, by re-structuring a lock based on reference to a portion of the memory the present invention retains a lock on a portion of the memory for a shorter duration than in the past and enables concurrent access of various portions of the memory.
The present invention determines the computer-based operation that the locks are safeguarding and re-establishes a lock structure based on the operations that are being safeguarded. More particularly, the present invention analyzes a critical code block to determine the region of the memory accessed by the critical code block and re-establishes access and safeguarding of the memory based on the operation related to the memory access. That is, the present invention re-establishes access by a threads-based program to a lock based reference to the memory. Thereby the present invention enables greater sharing of the computer memory by a more efficient access to the computer memory than in the past.
Other aspects and advantages of the present invention will become apparent from the following detailed description, taken in conjunction with the accompanying drawings, illustrating by way of example the principles of the invention.